package cxf.server.util;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.sql.Date;
import java.text.SimpleDateFormat;

/**
 * Created by Administrator on 2018/3/14.
 */
public class SqlDateAdapter extends XmlAdapter<String, java.sql.Date> {

    @Override
    public Date unmarshal(String v) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d = null;
        try {
            d = format.parse(v);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Date(d.getTime());
    }

    @Override
    public String marshal(Date v) throws Exception {
        String str = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            str = format.format(v);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
}
